﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DictationToolSilverlight.ViewModel;
using System.IO;

namespace DictationToolSilverlight.View
{
    public partial class MediaPlayerView : UserControl
    {
        public MediaPlayerView()
        {
            InitializeComponent();

            seekTo.MouseLeftButtonUp += new MouseButtonEventHandler(seekTo_MouseLeftButtonUp);
        }

        void seekTo_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var mediaPlayerViewModel = this.DataContext as MediaPlayerViewModel;
            mediaPlayerViewModel.SeekTo(e.GetPosition(seekTo).X / seekTo.ActualWidth);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            //dlg.Filter = "All Support Files(*.mp3;*.wma;*.wmv;*.avi;*.mp4) | *.mp3;*.wma;*.wmv;*.avi;*.mp4";
            dlg.Filter = "*.mp3 | *.mp3";

            if (dlg.ShowDialog() == true)
            {
                var mediaPlayerViewModel = this.DataContext as MediaPlayerViewModel;
                mediaPlayerViewModel.SourceUrl = dlg.File.FullName.Replace("\\","//");
            }
        }
    }
}
